home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Examples / Text / Sources / RulerFacet.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  7.0 KB  |  251 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                            RulerFacet.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Author:                        Anthone Burbidge
  7. //    Creation Date:        3/28/94
  8. //
  9. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  10. //
  11. //========================================================================================
  12.  
  13. // ----- Macintish Includes -----
  14.  
  15. #ifndef __TOOLUTILS__
  16. #include <ToolUtils.h>
  17. #endif
  18.  
  19. // ----- OpenDoc Includes -----
  20.  
  21. #ifndef _SHAPE_
  22. #include "Shape.h"
  23. #endif
  24.  
  25. // ----- Framework Includes -----
  26.  
  27. #ifndef FWUTIL_H
  28. #include "FWUtil.h"
  29. #endif
  30.  
  31. #ifndef FWRECT_H
  32. #include "FWRect.h"
  33. #endif
  34.  
  35. // ----- TextPart Includes -----
  36.  
  37. #ifndef _RulerObject_
  38. #include "RulerObject.h"
  39. #endif
  40.  
  41. #ifndef _RULERFACET_
  42. #include "RulerFacet.h"
  43. #endif
  44.  
  45. #ifndef _RULERFRAME_
  46. #include "RulerFrame.h"
  47. #endif
  48.  
  49. #ifndef _TEXTUTIL_
  50. #include "TextUtil.h"
  51. #endif
  52.  
  53. #ifndef _TEXTPART_
  54. #include "TextPart.h"
  55. #endif
  56.  
  57. #pragma segment TextPartSegment
  58.  
  59. //========================================================================================
  60. // CLASS CRulerFacet
  61. //========================================================================================
  62.  
  63. const RGBColor CRulerFacet::kGray =        { 0xB000, 0xB000, 0xB000 };
  64. const RGBColor CRulerFacet::kBlack =    { 0x0000, 0x0000, 0x0000 };
  65.  
  66. //----------------------------------------------------------------------------------------
  67. // CRulerFacet::CRulerFacet
  68. //----------------------------------------------------------------------------------------
  69.  
  70. CRulerFacet::CRulerFacet() :
  71.     FW_CFacet(),
  72.     fTextPart(NULL),
  73.     fSelectedTool(0)
  74. {
  75. }
  76.  
  77. //----------------------------------------------------------------------------------------
  78. // CRulerFacet::IRulerFacet
  79. //----------------------------------------------------------------------------------------
  80.  
  81. void CRulerFacet::IRulerFacet(XMPFacet* facet, CTextPart* textPart)
  82. {
  83.     InitFacet(facet);
  84.     fTextPart = textPart;
  85.         
  86.     // ----- Calculate the tool positions
  87.     FW_SPlatformRect toolArea;
  88.     short center = CTextPart::kRulerWidth / 2;
  89.     
  90.     toolArea.top = CTextPart::kRulerRulerHeight + 4;
  91.     toolArea.left = center - (CTextPart::kToolWidths + 4) * 2;
  92.     toolArea.bottom = toolArea.top + CTextPart::kToolHeights;
  93.     toolArea.right = toolArea.left + CTextPart::kToolWidths;
  94.         
  95.     // ----- Set the tool area rectangles
  96.     for (short i = 0; i < CTextPart::kNumberOfTools; i++)
  97.     {
  98.         fToolAreas[i] = toolArea;
  99.         toolArea.left += CTextPart::kToolWidths + 4;
  100.         toolArea.right += CTextPart::kToolWidths + 4;
  101.     }
  102. }
  103.  
  104. //----------------------------------------------------------------------------------------
  105. // CRulerFacet::~CRulerFacet
  106. //----------------------------------------------------------------------------------------
  107.  
  108. CRulerFacet::~CRulerFacet()
  109. {
  110. }
  111.  
  112. //----------------------------------------------------------------------------------------
  113. // CRulerFacet::Draw
  114. //----------------------------------------------------------------------------------------
  115.  
  116. void CRulerFacet::Draw(FW_CGraphicContext *gc)
  117. {
  118.     XMPShape* clipShape = ::NewXMPShape();
  119.     gc->GetClipShape(clipShape);
  120.  
  121.     ::EraseRgn(clipShape->GetQDRegion());
  122.     
  123.     CRulerFrame* frame = (CRulerFrame *) GetFrame();
  124.  
  125.     FW_CRect frameBounds;
  126.     frame->GetFrameShapeBounds(&frameBounds);
  127.  
  128.     FW_SPlatformRect qdFrameBounds = frameBounds;
  129.  
  130.     DrawBackground(clipShape->GetQDRegion(), qdFrameBounds);
  131.     DrawTools(clipShape->GetQDRegion(), qdFrameBounds);
  132.     DrawRuler(clipShape->GetQDRegion(), qdFrameBounds);
  133.     
  134.     delete clipShape;
  135. }
  136.  
  137. //----------------------------------------------------------------------------------------
  138. // CRulerFacet::DoMouseDown
  139. //----------------------------------------------------------------------------------------
  140.  
  141. FW_Boolean CRulerFacet::DoMouseDown(const FW_CPoint& where, XMPEventData event)
  142. {
  143. FW_UNUSED(event);
  144.  
  145.     FW_CGraphicContext di(this->GetXMPFacet());
  146.  
  147.     const CTextPart::Justification justifyTable[] = { kLeftJust, kCenterJust,
  148.                                                       kRightJust, kFullJust };
  149.     
  150.     for (short i = 0; i < CTextPart::kNumberOfTools; i++)
  151.     {
  152.         FW_CRect rect(fToolAreas[i]);
  153.         if (rect.Contains(where))
  154.         {
  155.             {
  156.                 CTextDrawInitiator di((CTextFacet *) fTextPart->GetActiveFrame()->GetActiveFacet());
  157.                 fTextPart->SetSelectionJustification(justifyTable[i]);
  158.             }
  159.             
  160.             if (i != fSelectedTool)
  161.             {
  162.                 FW_SPlatformRect invertRect = fToolAreas[fSelectedTool];
  163.                 ::InsetRect(&invertRect, 1, 1);
  164.                 ::InvertRect(&invertRect);
  165.                 
  166.                 invertRect = fToolAreas[i];
  167.                 ::InsetRect(&invertRect, 1, 1);
  168.                 ::InvertRect(&invertRect);
  169.             }
  170.             fSelectedTool = i;
  171.             break;
  172.         }
  173.     }
  174.     return true;
  175. }
  176.  
  177. //----------------------------------------------------------------------------------------
  178. // CRulerFacet::MouseEnter
  179. //----------------------------------------------------------------------------------------
  180.  
  181. void CRulerFacet::MouseEnter(const FW_CPoint& where)
  182. {
  183. FW_UNUSED(where);
  184.     SetCursor(&XMPASLMQDGlobals.arrow); 
  185. }
  186.  
  187. //----------------------------------------------------------------------------------------
  188. // CRulerFacet::DrawBackground
  189. //----------------------------------------------------------------------------------------
  190.  
  191. void CRulerFacet::DrawBackground(FW_PlatformRegion invalidRgn, const FW_SPlatformRect& boundingBox)
  192. {
  193. FW_UNUSED(invalidRgn);
  194.  
  195.     FW_SPlatformRect grayArea = boundingBox;
  196.     grayArea.top += CTextPart::kRulerRulerHeight;
  197.     
  198.     ::RGBForeColor(&kGray);
  199.     ::FillRect(&grayArea, &XMPASLMQDGlobals.black);
  200.     ::RGBForeColor(&kBlack);
  201.     ::PenNormal();
  202.  
  203.     ::MoveTo(boundingBox.left, boundingBox.bottom - 1);
  204.     ::LineTo(boundingBox.right, boundingBox.bottom - 1);
  205. }
  206.  
  207. //----------------------------------------------------------------------------------------
  208. // CRulerFacet::DrawTools
  209. //----------------------------------------------------------------------------------------
  210.  
  211. void CRulerFacet::DrawTools(FW_PlatformRegion invalidRgn, const FW_SPlatformRect& boundingBox)
  212. {
  213. FW_UNUSED(invalidRgn);
  214. FW_UNUSED(boundingBox);
  215.  
  216.     FW_CAcquireASLMResourceAccess aq;
  217.     
  218.     const CTextPart::Justification justifyTable[] = { kLeftJust, kCenterJust, kRightJust, kFullJust };
  219.     const CTextPart::Justification justify = fTextPart->GetSelectionJustification();
  220.     
  221.     // ----- Draw the tools
  222.     for (short resourceId = 2021; resourceId <= 2024; resourceId++)
  223.     {
  224.         PicHandle pictHandle = ::GetPicture(resourceId);
  225.         ::DrawPicture(pictHandle, &fToolAreas[resourceId - 2021]);
  226.         if (justifyTable[resourceId - 2021] == justify)
  227.         {
  228.             FW_SPlatformRect invertRect = fToolAreas[resourceId - 2021];
  229.             ::InsetRect(&invertRect, 1, 1);
  230.             ::InvertRect(&invertRect);
  231.             fSelectedTool = resourceId - 2021;
  232.         }
  233.     }
  234. }
  235.  
  236. //----------------------------------------------------------------------------------------
  237. // CRulerFacet::DrawRuler
  238. //----------------------------------------------------------------------------------------
  239.  
  240. void CRulerFacet::DrawRuler(FW_PlatformRegion invalidRgn, const FW_SPlatformRect& boundingBox)
  241. {
  242. FW_UNUSED(invalidRgn);
  243. FW_UNUSED(boundingBox);
  244.  
  245.     FW_CAcquireASLMResourceAccess aq;
  246.     
  247.     FW_SPlatformRect rulerArea = { 0, 0, CTextPart::kRulerHeight, CTextPart::kRulerWidth };
  248.     PicHandle rulerHandle = ::GetPicture(2001);
  249.     ::DrawPicture(rulerHandle, &rulerArea);
  250. }
  251.